package com.gordon.tips.util;

import org.apache.commons.lang.StringUtils;



public class Page {
	private int recordCount;

	private int pageCount;

	private int pageSize;

	private int start;

	private int currentPage;

	private int first = 1;

	private int next = 1;

	private int last = 1;

	private int previous = 1;

	public int getCurrentPage() {
		return currentPage;
	}

	public int getStart() {
		return start;
	}
	
	public Page(){
	}

	public Page(int recordCount, int pageSize, String currentPage) {
		int pageCount = (recordCount + pageSize - 1) / pageSize;
		if (pageCount == 0) {
			pageCount = 1;
		}
		if (StringUtils.isBlank(currentPage) || Integer.parseInt(currentPage) < 2) {
			currentPage = "1";
		} else if (Integer.parseInt(currentPage) > pageCount) {
			currentPage = String.valueOf(pageCount);
		}
		this.currentPage = Integer.parseInt(currentPage);
		this.start = (this.currentPage - 1) * pageSize;
		this.recordCount = recordCount;
		this.pageSize = pageSize;
		this.pageCount = pageCount;
		first = 1;
		last = pageCount;
		next = this.currentPage != pageCount ? this.currentPage + 1 : this.currentPage;
		previous = this.currentPage != 1 ? this.currentPage - 1 : this.currentPage;
	}

	public int getPageCount() {
		return pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public int getFirst() {
		return first;
	}

	public int getLast() {
		return last;
	}

	public int getNext() {
		return next;
	}

	public int getPrevious() {
		return previous;
	}
}